package cn.wendellup.bootStrap.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import cn.wendellup.bootStrap.dao.contract.IAppParameterDao;
import cn.wendellup.bootStrap.valueobject.entity.AdvDetail;
import cn.wendellup.bootStrap.valueobject.entity.AppParameter;

@Repository
public class AppParameterDaoImpl implements IAppParameterDao {

	private static Logger logger = Logger.getLogger(AppParameterDaoImpl.class);

	private static final String STR_SELECT_PARAMETER_APP = 
			" id, parent_id, type, name, param, sort, enable, depth, remark,"
			+ " pic_id, begin_time, end_time, update_time, operator_id ";
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<Integer> listAppParameterIdsByParentId(Integer parentId) {
//		List<Integer> appParameterIds = new ArrayList<Integer>();
		String sql = " select id from t_parameter_app where parent_id = %1$d ";
		sql = String.format(sql, parentId);
		logger.info(sql);
		return jdbcTemplate.queryForList(sql, Integer.class);
		
//		List<Map<String, Object>> queryResult = jdbcTemplate.queryForList(sql);
//		for (Map<String, Object> map : queryResult) {
//			Integer id = (Integer) map.get("id");
//			appParameterIds.add(id);
//		}
//		return appParameterIds;
	}

	@Override
	public AppParameter getAppParameterById(Integer id) {
		String sqlOrginal = " select "
				+ STR_SELECT_PARAMETER_APP
				+ " from t_parameter_app where id = %1$d "; 
		final String sql = String.format(sqlOrginal, id);
		logger.info(sql);
		AppParameter appParameter = jdbcTemplate.queryForObject(sql, new AppParameter());
		return appParameter;
	}

}
